// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// image_manipulator allows various color manipulations on an image

#ifndef IMAGE_MANIPULATOR_H_
#define IMAGE_MANIPULATOR_H_

#include <string>
#include <memory>
#include "compat.h"
#include "image.h"
#include "hue_range.h"

namespace harmonizer {

class ImageManipulator {
 public:
  // No default ctor. Only way to create the object is by supplying an input
  // image or filename. Will fail on invalid input.
  explicit ImageManipulator(const std::string& file_name);
  explicit ImageManipulator(std::unique_ptr<Image> raw_image);

  virtual ~ImageManipulator();

  // Create a negative of the given image
  void NegateImage();

  // Fit an image to a given hue range
  bool FitImageToHueRange(const HueRange& hue_range);
  bool FitImageToHueRange(const HueRange& hue_range,
                          HueRange::HueFitMethod fit_method);

  // Write the image to a file
  bool WriteImageToFile(const std::string& file_name);

  // Get the image as RawImage
  std::unique_ptr<Image> GetRawImageCopy() const;

  // Compare two image manipulators. The two manipulators are considered equal
  // if the underlying RawImages are equal.
  bool Equals(const ImageManipulator& other) const;

  // Create a "label image" which runs graph-cut on the image and outputs the
  // labeling, using a specific HueRange().
  bool CreateLabelImage(const HueRange& hue_range,
                        Image* outputImage) const;
  // 'lambda' is used for the mincut labeling method. This parameter determines
  // the relative weight of pixel gradient vs. distance from target hues in the
  // optimization. Default value == 1.
  bool CreateLabelImage(const HueRange& hue_range,
                        Image* outputImage,
                        float lambda) const;

 private:
  // Internal representation of our image
  std::unique_ptr<Image> raw_image_;

  // Disallow copy and assignment.
  ImageManipulator(const ImageManipulator& toCopy);
  ImageManipulator& operator=(const ImageManipulator& toCopy);
};

}  // namespace harmonizer

#endif  // IMAGE_MANIPULATOR_H_
